package com.example.config;

import com.example.aop.BoyAspect;
import com.example.beans.Boy;
import com.example.beans.Girl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@Configuration
@EnableAspectJAutoProxy
public class AppConfig {

    /**
     * boy和girl之间存在循环依赖
     *
     * 如果没有注释掉@DependsOn("girl")和@DependsOn("boy"), 容器启动的时候会抛异常:
     * org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'girl' defined in com.example.config.AppConfig: Circular depends-on relationship between 'girl' and 'boy'
     */

    @Bean
//    @DependsOn("girl")
    public Boy boy(){
        return new Boy();
    }

    @Bean
//    @DependsOn("boy")
    public Girl girl(){
        return new Girl();
    }

    @Bean
    public BoyAspect boyAspect(){
        return new BoyAspect();
    }
}
